package com.szxy.configclient;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: zwz
 * @Date:2020/7/2 10:07
 * @Description:PACKAGE_NAME
 * @Version:1.0
 **/
@SpringBootApplication
@EnableDiscoveryClient
@RefreshScope // 表示配置文件更新后可以重新加载
@RestController
public class ConfigClientServiceApplication {

    @Value("${user.name}")
    private String userName;
    @Value("${user.age}")
    private String userAge;
    @Value("${girl.name}")
    private String girlName;
    @Value("${girl.age}")
    private String girlAge;

    public static void main(String[] args) {
        SpringApplication.run(ConfigClientServiceApplication.class, args);
    }

    @GetMapping("/config/get")
    public ResponseEntity getConfig() {
        return ResponseEntity.ok(String.format("获取配置信息 : userName = %s, userAge = %s", this.userName, this.userAge));
    }

    @GetMapping("/girl")
    public ResponseEntity getGirlIfno() {
        return ResponseEntity.ok(String.format("girlName = %s, girlAge = %s", this.girlName, this.girlAge));
    }
}
